<template>
	<a-card :bordered="false">
		<div class="table-page-search-wrapper">
			<a-form layout="inline">
				<a-row :gutter="48">

					<a-col :md="8" :sm="24">
						<a-form-item label="发货单号">
							<a-input v-model="queryParam.orderNumber" placeholder="请输入发货单号" />
						</a-form-item>
					</a-col>

					<!-- <a-col :md="8" :sm="24">
						<a-form-item label="生产单号">
							<a-input v-model="queryParam.sourceOrderNumber" placeholder="请输入生产单号" />
						</a-form-item>
					</a-col> -->
					<a-col :md="8" :sm="24">
						<a-form-item label="发货时间">
							<a-range-picker v-model="createTime" :value-format="'YYYY-MM-DD HH:mm:ss'" @change="createTimeChange" />
						</a-form-item>
					</a-col>
					<a-col :md="24" :sm="24">
						<a-form-item label="归属公司：">
							<FCOrgRadioGroup v-model="queryParam.orgId" :filter-types="[$businessEnum.ORG_TYPE_ENUM.COMPANY.id]" />
						</a-form-item>
					</a-col>
					<a-col :md="!advanced && 8 || 24" :sm="24">
						<span class="table-page-search-submitButtons"
							:style="advanced && { float: 'right', overflow: 'hidden' } || {}">
							<a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
							<a-button style="margin-left: 8px"
								@click="() => { queryParam.orderNumber = null; queryParam.sourceOrderNumber = null; queryParam.startTime = null; queryParam.endTime = null; createTime = null; $refs.table.refresh() }">重置</a-button>
						</span>
					</a-col>
				</a-row>
			</a-form>
		</div>

		<div class="table-operator">
		</div>

		<s-table ref="table" size="default" :columns="columns" :data="loadData" :alert="true"
			:rowKey="(record) => record.code" :rowSelection="null">

			<span slot="action" slot-scope="text, record">
				<a @click="$refs.deliverModal.show(record)">详情</a>
			</span>
		</s-table>

		<deliver-modal ref="deliverModal" @ok="handleOk" />

	</a-card>
</template>

<script>
import { STable } from '@/components'
import { page } from '@/api/modular/main/emsorder/emsOrderManage'
import FCOrgRadioGroup from '@/components/FcOrgRadioGroup/FCOrgRadioGroup'
import deliverModal from './deliverModal'


export default {
	components: {
		STable,
		FCOrgRadioGroup,
		deliverModal,
	},
	data() {
		return {
			advanced: false, // 高级搜索 展开/关闭
			queryParam: {},  // 查询参数
			createTime: null,
			columns: [       // 表头
				{
					title: '序号', width: '80px',
					dataIndex: '',
					customRender: (text, record, index) => `${index + 1}`
				},
				{
					title: '发货单号',
					dataIndex: 'orderNumber',
				},
				{
					title: '归属子公司',
					dataIndex: 'orgName',
				},
				{
					title: '发货时间',
					dataIndex: 'createTime',
				},
				{
					title: '操作人',
					dataIndex: 'createUserName',
				},
				{
					title: '操作',
					dataIndex: 'action',
					width: '',
					scopedSlots: { customRender: 'action' }
				}
			],
			// 加载数据方法 必须为 Promise 对象
			loadData: parameter => {
				this.queryParam.orderType = this.$businessEnum.ORDER_TYPE_ENUM.deliverOrder.id
				this.queryParam.isOverseasStore = 'Y'
				return page(Object.assign(parameter, this.queryParam)).then((res) => {
					return res.data
				})
			},
			scheduleProductionVisible: false,
			selectedRowKeys: [],
			selectedRows: [],
			defaultExpandedKeys: [],
			replaceFields: {
				key: 'id',
			},
			urlParam: {},
			columnsType: '',
			suppliers: [],
			orgs: [],
			viewState: '',
			materialType: '',
		}
	},
	created() { },
	methods: {
		toggleAdvanced() {
			this.advanced = !this.advanced
		},
		createTimeChange(e) {
			console.log(e);
			this.queryParam.startTime = e[0].split(" ")[0] + " 00:00:00";
			this.queryParam.endTime = e[1].split(" ")[0] + " 23:59:59";
		},
		handleOk() {
			this.$refs.table.refresh()
		},
		onSelectChange(selectedRowKeys, selectedRows) {
			this.selectedRowKeys = selectedRowKeys
			this.selectedRows = selectedRows
		},
	}
}
</script>

<style lang="less">
.table-operator {
	margin-bottom: 18px;
}

button {
	margin-right: 8px;
}
</style>
